app_family.controller("controller_orderservsel", function($scope, $rootScope, httpRequest, $location) {
	$rootScope.$broadcast('currentModule', 'page_orderlist');
	$rootScope.$broadcast('footerFlag', false); // 是否显示底部导航
	$scope.imagebasepath = imagebasepath; // 资源图片根目录
	$scope.servTypeIndex = 0;
	$scope.servIndex = null;
	$scope.servName = null;
	
	data_sessionStorage = JSON.parse(sessionStorage.getItem('data_sessionStorage'));
	
	/**
	 * 判断是否用手机登录过
	 */
	if (data_sessionStorage) {
		var familyPhone = data_sessionStorage.familyInfo.phone;
		if (familyPhone == '' || familyPhone == null) {
			window.location.replace(basepath + 'login.html');
			return;
		}
	} else {
		window.location.replace(basepath + 'login.html');
		return;
	}
	
	/**
	 * 根据经纬度，查询当前范围内的所有服务项目
	 */
	$scope.getAllService = function () {
		httpRequest.getAllService({
			lon : data_sessionStorage.order_service.older.lon,
			lat : data_sessionStorage.order_service.older.lat
		}, function (data) {
			if (data.success === true) {
				$scope.servList = data.obj;
				
				/**
				 * 初始化 选日期控件
				 */
				var nd = new Date();
	        	nd.setDate(nd.getDate() + 2);
	        	nd.setHours(23);  // 服务时间限制选择 三天内
	        	
				$('#selTime').mobiscroll().calendar({
			        theme: 'mobiscroll',  
			        lang: 'zh', 
			        display: 'bottom',   
			        controls: ['datetime'],
			        dateFormat : 'yy-mm-dd hh:mm',
			        minDate : new Date(),
			        maxDate : nd,
			        showNow : false,
			        setText: '',
			        layout : 'fixed',
			        setText: '确定',
			        cancelText: '取消',
			        onBeforeShow: function (inst) {
			        	inst.settings.wheels[1].splice(1,1); //去掉'分钟'列表
			        },
			        headerText: function (valueText) {
	                    array = valueText.split('-');
	                    return '服务时间：' + array[1] + "月" + array[2].substring(0, 2) + "日" + array[2].substring(9, 11) + "点";
	                },
			        onSelect: function (valueText, inst) {
			        	var arr = valueText.split('-');
			        	var year = arr[0],
			        		month = arr[1],
			        		day = arr[2].substring(0, 2),
			        		hour = array[2].substring(9, 11);
			        	
			        	// 保存服务时间
			        	data_sessionStorage = JSON.parse(sessionStorage.getItem('data_sessionStorage'));
			        	data_sessionStorage.order_service.service.time = year + '-' + month + '-' + day + ' ' + hour + ':00:00';
			    		sessionStorage.setItem('data_sessionStorage', JSON.stringify(data_sessionStorage));
			        	
			        	// 跳转到选商家
			    		$location.path('/orderstoresel');
			    		$scope.$apply();
			        },
			        onCancel : function (valueText, inst) {
			        	$scope.servIndex = null;
			        	$scope.$apply();
			        }
				});
			} else if (data.success === false) {
				$.dialog.showToast({msgTxt : data.msg});
			}
		});
	};
	
	/**
	 * 根据账号，查询个人信息
	 */ 
	httpRequest.getOlderInfo({
		account : data_sessionStorage.order_service.older.account
	}, function (data) {
		if (data.success === true) {
			$scope.order_serviceObj = data.obj;
			// 根据经纬度，查询当前范围内的所有服务项目
			$scope.getAllService();
		} else if (data.success === false) {
			$.dialog.showToast({msgTxt : data.msg});
		}
	});
	
	/**
	 * 选择服务类别
	 */
	$scope.servTypeSel = function (index, name) {
		$scope.servTypeIndex = index;
		$scope.servTypeName = name;
	};
	
	/**
	 * 选择服务
	 */
	$scope.toSelStore = function (code, name) {
		$scope.servIndex = code;
		// 保存服务code
		data_sessionStorage.order_service.service.code = code;
		data_sessionStorage.order_service.service.name = name;
		sessionStorage.setItem('data_sessionStorage', JSON.stringify(data_sessionStorage));
		
		$('#selTime').mobiscroll('show');
		return false;
	};
	
	
});